<%@page import="multiface.awwadco.jpa.File"%>
<%@page import="java.util.List"%>
<%@page import="java.util.LinkedList"%>
<%@page import="multiface.awwadco.jpa.Prodotto"%>
<%@page import="multiface.awwadco.jpa.PersistenceManager"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="javax.persistence.EntityManager"%>
<div class="body_resize">
    <div class="body">
        <%
            EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
            EntityManager em = emf.createEntityManager();

            List<Prodotto> list = em.createQuery("SELECT p FROM Prodotto p WHERE p.homepage=true AND p.stato=:stat", Prodotto.class).setParameter("stat", "VISIBILE").getResultList();

            for (Prodotto p : list) {
                em.refresh(p);
                String src = "engine/img/notImage.png";
                List<File> lf = p.getFileList();
                if (lf.size() > 0) {
                    src = "GetImageServlet?w=196&fid=" + lf.get(0).getIdfile();
                    for (File f : lf) {
                        if (f.getCopertina()) {
                            src = "GetImageServlet?w=196&fid=" + f.getIdfile();
                        }
                    }
                }

                String desc = "";
                if (p.getDescrizioneHomepage() != null) {
                    desc = p.getDescrizioneHomepage();
                }
        %>
        <div class="home-prod">
            
            <div class="title"><a href="?page=product&pid=<%=p.getIdprodotto()%>"><%=p.getNome()%></a></div>
            <div class="image"><a href="?page=product&pid=<%=p.getIdprodotto()%>"><img src="<%=src%>" alt="<%=p.getNome()%>" class="floated" border="0"></a></div>
            <div class="desc"><%=desc%></div>
            <div class="detail"><a href="?page=product&pid=<%=p.getIdprodotto()%>">View Product Details</a></div>

            <div class="clr"></div>
        </div>
        <%}%>
        <div class="clr"></div>
    </div>
    <div class="clr"></div>
</div>